﻿using HBase;
using hconnect;
using hCommand;
using MongoDB.Bson;
using System.Collections.Generic;

namespace Controller
{

    public class CarrierStatus : SignalStatus<CarrierSignalStatus>
    {

        public CarrierStatus() : base(null, 1)
        {

        }


        private static List<string> nameList = new List<string>() { "inHeightStatus", "inWeightValue", "inScanArrive", "materialIsExist", "inMaterialArrive"};
        private static List<string> nameList2 = new List<string>() { };
        public override List<BsonDocument> getDef(BsonDocument his, BsonDocument document)
        {
            List<BsonDocument> list = new List<BsonDocument>();
            BsonDocument oldDoc = JsonUtil.getDoc(his, "c");
            BsonDocument nowDoc = JsonUtil.getDoc(document, "c");
            IEnumerable<BsonElement> elements = nowDoc.Elements;

            foreach (BsonElement be in elements)
            {
                string name = be.Name;
                BsonDocument oldvalue = JsonUtil.getDoc(oldDoc, name);
                BsonDocument nowv = be.Value.AsBsonDocument;
                BsonDocument bdc = JsonUtil.getDef(oldvalue, nowv, nameList, nameList2);
                if (bdc != null)
                {
                    bdc.Add("eId", "STN:" + JsonUtil.getStr(nowv, "p"));
                    bdc.Add("ticks", time);
                    bdc.Add("keyCode", JsonUtil.getStr(bdc, "no") + "," + JsonUtil.getStr(nowv, "c"));
                    list.Add(bdc);
                }
            }
            return list;
        }


        public override string getError()
        {
            return null;
        }







    }
}
